<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../static/vue/2.6.10/vue.js" type="text/javascript"></script>
    <script src="../static/vuex/3.1.1/vuex.js" type="text/javascript"></script>
    <title>vuex</title>
</head>
<body>
    <div id="app">
        <p>{{count}}</p>
        <p>
            <button @click="increment">+</button>
            <button @click="decrement">-</button>
        </p>
    </div>
</body>
<script type="text/javascript">
    const store = new Vuex.Store({
        state: {
            count: 0
        },
        mutations: {
            increment: state => state.count++,
            decrement: state => state.count--
        }
    });

    const vm = new Vue({
        el: '#app',
        computed: {
            count() {
                return store.state.count
            }
        },
        methods: {
            increment() {
                store.commit('increment')
            },
            decrement() {
                store.commit('decrement')
            }
        }
    })
</script>
</html>
